﻿namespace CodingExercises._41_50;

public class Sort
{
    // 排序算法
    public static void Method(int[] numbers)
    {
        if (numbers is null)
        {
            throw new ArgumentNullException(nameof(numbers), "Array cannot be null.");
        }

        int n = numbers.Length;
        for (int i = 0; i < n - 1; ++i)
        {
            bool swapped = false;
            for (int j = 0; j < n - 1 - i; j++)
            {
                if (numbers[j] > numbers[j + 1])
                {
                    int tmp = numbers[j];
                    numbers[j] = numbers[j + 1];
                    numbers[j + 1] = tmp;
                    swapped = true;
                }
            }

            if (!swapped)
            {
                break;
            }
        }
    }
}